/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tmp.ac.lib.tools;

/**
 *
 * @author ismail
 */
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
/*import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;*/
import java.text.SimpleDateFormat;
import java.util.Calendar;
/*import static java.nio.file.StandardCopyOption.*;
import java.nio.file.WatchEvent.Kind;
import java.nio.file.WatchEvent.Modifier;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;*/
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;

public class files {

    public void createfolder(String folname, String name, String srcfold) {
        String srcfolder = srcfold;
        String folderName = folname;
        String fname = name;
        Calendar currentDate = Calendar.getInstance();
        SimpleDateFormat formatter =
                new SimpleDateFormat("MM-dd-yy");
        String dateNow = formatter.format(currentDate.getTime());
        System.out.println(dateNow);
        File srcFolder = new File(srcfolder);
        File destFolder = new File("//" + folderName + "/ABS Shared Network WLAN/Avventuro Users - ReadWrite/1 - BackUp/" + fname + "/" + dateNow);

        //make sure source exists  
        if (!srcFolder.exists()) {

            System.out.println("Directory does not exist.");
            //just exit  
            System.exit(0);

        } else {

            try {
                copyFolder(srcFolder, destFolder);
            } catch (IOException e) {
                e.printStackTrace();
                //error, just exit  
                System.exit(0);
            }
        }

        System.out.println("Done");
    }

    public static void copyFolder(File src, File dest)
            throws IOException {

        if (src.isDirectory()) {

            //if directory not exists, create it  
            if (!dest.exists()) {
                dest.mkdir();
                System.out.println("Directory copied from "
                        + src + "  to " + dest);
            }

            //list all the directory contents  
            String files[] = src.list();

            for (String file : files) {
                //construct the src and dest file structure  
                File srcFile = new File(src, file);
                File destFile = new File(dest, file);
                //recursive copy  
                copyFolder(srcFile, destFile);
            }

        } else {
            //if file, then copy it  
            //Use bytes stream to support all file types  
            InputStream in = new FileInputStream(src);
            OutputStream out = new FileOutputStream(dest);

            byte[] buffer = new byte[1024];

            int length;
            //copy the file content in bytes   
            while ((length = in.read(buffer)) > 0) {
                out.write(buffer, 0, length);
            }

            in.close();
            out.close();
            System.out.println("File copied from " + src + " to " + dest);
        }
    }

    public static void copyfile(String srFile, String srtitle, String dtFile) {
/*        Path f1 = FileSystems.getDefault().getPath(srFile, srtitle);
        Path f2 = FileSystems.getDefault().getPath(dtFile, srtitle);
        try {
            Files.copy(f1, f2, REPLACE_EXISTING);
              uiUtil.sendMessage(null, srFile, dtFile);
            
        } catch (IOException ex) {
           
            uiUtil.sendMessage(null, ex.getMessage(), ex.getMessage());
        }*/
    }
    
    
    
        public Image getScaledImage(Image srcImg, int w, int h) {
        BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = resizedImg.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g2.drawImage(srcImg, 0, 0, w, h, null);
        g2.dispose();
        return resizedImg;
    }
}
